<!--  -->
<template>
  <div class="">
    <el-button @click="clickHandle">防抖</el-button>
    <el-button @click="clickHandle1">节流</el-button>
  </div>
</template>

<script setup lang="ts">
import {} from 'vue';
function debounce(fn, wait){
  let timer = null;
  return function(...args){
    clearTimeout(timer);
    timer = setTimeout(() => {
      fn.apply(this, args);
    }, wait);
  };
}

function throttle(fn, wait){
  let timer;
  return function(...args){
    if(!timer){
      timer = true;
      fn.apply(this, args);
      setTimeout(() => {
        timer = false;

      }, wait);
    }
  };
}
const clickHandle = debounce(() => {
  console.log('点击事件触发了');

}, 1000);

const clickHandle1 = throttle(() => {
  console.log('节流触发了');

}, 1000);
</script>

<style lang="scss" scoped>

</style>
